import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * docType.js - 单据权限定义 service
 * @date: 2018-10-29
 */
import request from 'utils/request';
import { parseParameters, isTenantRoleLevel, getCurrentOrganizationId } from 'utils/utils';
import { CPAAS_IAM } from 'utils/config';
var tenantId = getCurrentOrganizationId();

function docTypeApi() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/doc-types") : "doc-types";
}
/**
 * 查询单据类型定义
 * @param {Object} params - 查询参数
 */


export function queryDocType(_x) {
  return _queryDocType.apply(this, arguments);
}
/**
 * 查询单据类型定义详情
 * @param {Object} params - 查询参数
 */

function _queryDocType() {
  _queryDocType = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(isTenantRoleLevel() ? "".concat(tenantId, "/doc-types") : 'doc-types'), {
              method: 'GET',
              query: parseParameters(params)
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryDocType.apply(this, arguments);
}

export function queryDocTypeDetail(_x2) {
  return _queryDocTypeDetail.apply(this, arguments);
}
/**
 * 新增单据类型定义
 * @param {Object} params - 新增单据类型定义
 */

function _queryDocTypeDetail() {
  _queryDocTypeDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(docTypeApi(), "/").concat(params.docTypeId), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _queryDocTypeDetail.apply(this, arguments);
}

export function addDocType(_x3) {
  return _addDocType.apply(this, arguments);
}
/**
 * 更新单据类型定义
 * @param {Object} params - 更新单据类型定义
 */

function _addDocType() {
  _addDocType = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    var body;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            body = params.body;
            return _context3.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(docTypeApi()), {
              method: 'POST',
              body: body
            }));

          case 2:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _addDocType.apply(this, arguments);
}

export function updateDocType(_x4) {
  return _updateDocType.apply(this, arguments);
}
/**
 * 查询单据类型权限维度
 * @param {Object} params - 查询参数
 */

function _updateDocType() {
  _updateDocType = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    var body;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            body = params.body;
            return _context4.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(docTypeApi()), {
              method: 'PUT',
              body: body
            }));

          case 2:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updateDocType.apply(this, arguments);
}

export function queryDocTypeAuth(_x5) {
  return _queryDocTypeAuth.apply(this, arguments);
}
/**
 * 更新单据类型权限维度
 * @param {Object} params - 更新单据类型权限维度数据
 */

function _queryDocTypeAuth() {
  _queryDocTypeAuth = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(docTypeApi(), "/").concat(params.docTypeId, "/auth-dim"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _queryDocTypeAuth.apply(this, arguments);
}

export function updateDocTypeAuth(_x6) {
  return _updateDocTypeAuth.apply(this, arguments);
}

function _updateDocTypeAuth() {
  _updateDocTypeAuth = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    var docTypeId, body;
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            docTypeId = params.docTypeId, body = params.body;
            return _context6.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(docTypeApi(), "/").concat(docTypeId, "/auth-dim/save"), {
              method: 'POST',
              body: body
            }));

          case 2:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _updateDocTypeAuth.apply(this, arguments);
}